package com.bat.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;

/**
 * @Description:
 * @Author: zpf
 * @Date: 2019/12/7 下午4:47
 */
@Service
@RocketMQMessageListener(topic = "topic", consumerGroup = "topic-zpf-consumer",
    customizedTraceTopic = "my-trace-topic")
@Slf4j
public class RocketMqListenerAck implements RocketMQListener<MessageExt>, RocketMQPushConsumerLifecycleListener {

    @Override
    public void onMessage(MessageExt message) {
        log.info("接收的消息{}", new String(message.getBody(), StandardCharsets.UTF_8));
        throw new RuntimeException("抛出消息异常");
    }

    @Override
    public void prepareStart(DefaultMQPushConsumer consumer) {

    }
}
